//
//  GoodListViewController.m
//  B2C
//
//  Created by xiaowu on 2017/8/7.
//  Copyright © 2017年 lixiaolong. All rights reserved.
//

#import "GoodListViewController.h"
#import "CommodityCell.h"
#import "CommodityModel.h"

@interface GoodListViewController () <UITableViewDataSource, UITableViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;
@end

@implementation GoodListViewController

- (instancetype)init {
    self = [super init];
    if (self) {
        _dataArr = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configureUI];
}

- (void)configureUI {
    self.view.backgroundColor = [UIColor backgroundColor];
    self.tableView.backgroundColor = [UIColor backgroundColor];
    self.tableView.dataSource  = self;
    self.tableView.delegate = self;
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate  = self;
    
    [self.tableView registerClass:[CommodityCell class] forCellReuseIdentifier:@"cell"];
}

- (void)loadListData {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters safeObjectForKey:@""];
    
//    [MYAFNetworking POST:<#(NSString * _Nullable)#> parameters:parameters success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
//        
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
//        
//    } isNeedCache:YES];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [CommodityCell getRowNumberWithItemArr:self.dataArr];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CommodityCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    [cell setValueForCell:[CommodityCell getCellItemArr:self.dataArr withIndexPath:indexPath]];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [CommodityCell getHeight];
}

#pragma mark - DZNEmptyDataSetSource, DZNEmptyDataSetDelegate
//主提示标题
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    return [[NSAttributedString alloc] initWithString:@"暂无商品"
                                           attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0],
                                                        NSForegroundColorAttributeName:[UIColor grayTextColor]}];
}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    [self loadListData];
}

@end
